home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / DirectShow_WinXP / VMR / Renderless / commands.cpp < prev    next >
C/C++ Source or Header  |  2001-10-08  |  6KB  |  265 lines

  1. //------------------------------------------------------------------------------
  2. // File: commands.cpp
  3. //
  4. // Desc: DirectShow sample code - Processes commands from the user
  5. //
  6. // Copyright (c) 1994-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9. #include <streams.h>
  10. #include <mmreg.h>
  11. #include <commctrl.h>
  12.  
  13. #include "project.h"
  14. #include <stdio.h>
  15.  
  16. extern void RepositionMovie(HWND hwnd);
  17.  
  18. extern TCHAR       g_achFileName[];
  19. extern CMpegMovie  *pMpegMovie;
  20.  
  21.  
  22. /******************************Public*Routine******************************\
  23. * ProcessOpen
  24. *
  25. \**************************************************************************/
  26. void
  27. ProcessOpen(
  28.     TCHAR *achFileName,
  29.     BOOL bPlay
  30.     )
  31. {
  32.     /*
  33.     ** If we currently have a video loaded we need to discard it here.
  34.     */
  35.     if(g_State & VCD_LOADED)
  36.     {
  37.         VcdPlayerCloseCmd();
  38.     }
  39.  
  40.     lstrcpy(g_achFileName, achFileName);
  41.  
  42.     pMpegMovie = new CMpegMovie(hwndApp);
  43.     if(pMpegMovie)
  44.     {
  45.         HRESULT hr = pMpegMovie->OpenMovie(g_achFileName);
  46.         if(SUCCEEDED(hr))
  47.         {
  48.             TCHAR achTmp[MAX_PATH];
  49.  
  50.             wsprintf(achTmp, IdStr(STR_APP_TITLE_LOADED), g_achFileName);
  51.             g_State = (VCD_LOADED | VCD_STOPPED);
  52.  
  53.             RepositionMovie(hwndApp);
  54.             InvalidateRect(hwndApp, NULL, TRUE);
  55.  
  56.             if(bPlay)
  57.             {
  58.                 pMpegMovie->PlayMovie();
  59.             }
  60.         }
  61.         else
  62.         {
  63.             MessageBox(hwndApp, TEXT("Failed to open the movie! "),
  64.                 IdStr(STR_APP_TITLE), MB_OK);
  65.  
  66.             pMpegMovie->CloseMovie();
  67.             delete pMpegMovie;
  68.             pMpegMovie = NULL;
  69.         }
  70.     }
  71.  
  72.     InvalidateRect(hwndApp, NULL, FALSE);
  73.     UpdateWindow(hwndApp);
  74. }
  75.  
  76.  
  77. /******************************Public*Routine******************************\
  78. * VcdPlayerOpenCmd
  79. *
  80. \**************************************************************************/
  81. BOOL
  82. VcdPlayerOpenCmd(
  83.     void
  84.     )
  85. {
  86.     static OPENFILENAME ofn;
  87.     static BOOL fFirstTime = TRUE;
  88.     BOOL fRet;
  89.     TCHAR achFileName[MAX_PATH];
  90.     TCHAR achFilter[MAX_PATH];
  91.     LPTSTR lp;
  92.  
  93.     if(fFirstTime)
  94.     {
  95.         ofn.lStructSize = sizeof(ofn);
  96.         ofn.hwndOwner = hwndApp;
  97.         ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST |
  98.             OFN_SHAREAWARE | OFN_PATHMUSTEXIST;
  99.     }
  100.  
  101.     lstrcpy(achFilter, IdStr(STR_FILE_FILTER));
  102.     ofn.lpstrFilter = achFilter;
  103.  
  104.     /*
  105.     ** Convert the resource string into to something suitable for
  106.     ** GetOpenFileName ie.  replace '#' characters with '\0' characters.
  107.     */
  108.     for(lp = achFilter; *lp; lp++)
  109.     {
  110.         if(*lp == TEXT('#'))
  111.         {
  112.             *lp = TEXT('\0');
  113.         }
  114.     }
  115.  
  116.     ofn.lpstrFile = achFileName;
  117.     ofn.nMaxFile = sizeof(achFileName) / sizeof(TCHAR);
  118.     ZeroMemory(achFileName, sizeof(achFileName));
  119.  
  120.     fRet = GetOpenFileName(&ofn);
  121.     if(fRet)
  122.     {
  123.         fFirstTime = FALSE;
  124.         ProcessOpen(achFileName);
  125.     }
  126.  
  127.     return fRet;
  128. }
  129.  
  130.  
  131. /******************************Public*Routine******************************\
  132. * VcdPlayerCloseCmd
  133. *
  134. \**************************************************************************/
  135. BOOL
  136. VcdPlayerCloseCmd(
  137.     void
  138.     )
  139. {
  140.     if(pMpegMovie)
  141.     {
  142.         g_State = VCD_NO_CD;
  143.         pMpegMovie->StopMovie();
  144.         pMpegMovie->CloseMovie();
  145.  
  146.         delete pMpegMovie;
  147.         pMpegMovie = NULL;
  148.     }
  149.  
  150.     // Redraw main window
  151.     InvalidateRect(hwndApp, NULL, FALSE);
  152.     UpdateWindow(hwndApp);
  153.  
  154.     return TRUE;
  155. }
  156.  
  157. /******************************Public*Routine******************************\
  158. * VcdPlayerPlayCmd
  159. *
  160. \**************************************************************************/
  161. BOOL
  162. VcdPlayerPlayCmd(
  163.     void
  164.     )
  165. {
  166.     BOOL fStopped = (g_State & VCD_STOPPED);
  167.     BOOL fPaused  = (g_State & VCD_PAUSED);
  168.  
  169.     if((fStopped || fPaused))
  170.     {
  171.         if(pMpegMovie)
  172.         {
  173.             pMpegMovie->PlayMovie();
  174.         }
  175.  
  176.         g_State &= ~(fStopped ? VCD_STOPPED : VCD_PAUSED);
  177.         g_State |= VCD_PLAYING;
  178.     }
  179.  
  180.     return TRUE;
  181. }
  182.  
  183.  
  184. /******************************Public*Routine******************************\
  185. * VcdPlayerStopCmd
  186. *
  187. \**************************************************************************/
  188. BOOL
  189. VcdPlayerStopCmd(
  190.     void
  191.     )
  192. {
  193.     BOOL fPlaying = (g_State & VCD_PLAYING);
  194.     BOOL fPaused  = (g_State & VCD_PAUSED);
  195.  
  196.     if((fPlaying || fPaused))
  197.     {
  198.         if(pMpegMovie)
  199.         {
  200.             pMpegMovie->StopMovie();
  201.             pMpegMovie->SetFullScreenMode(FALSE);
  202.         }
  203.  
  204.         g_State &= ~(fPlaying ? VCD_PLAYING : VCD_PAUSED);
  205.         g_State |= VCD_STOPPED;
  206.     }
  207.     return TRUE;
  208. }
  209.  
  210.  
  211. /******************************Public*Routine******************************\
  212. * VcdPlayerPauseCmd
  213. *
  214. \**************************************************************************/
  215. BOOL
  216. VcdPlayerPauseCmd(
  217.     void
  218.     )
  219. {
  220.     BOOL fPlaying = (g_State & VCD_PLAYING);
  221.     BOOL fPaused  = (g_State & VCD_PAUSED);
  222.  
  223.     if(fPlaying)
  224.     {
  225.         if(pMpegMovie)
  226.         {
  227.             pMpegMovie->PauseMovie();
  228.         }
  229.  
  230.         g_State &= ~VCD_PLAYING;
  231.         g_State |= VCD_PAUSED;
  232.     }
  233.     else if(fPaused)
  234.     {
  235.         if(pMpegMovie)
  236.         {
  237.             pMpegMovie->PlayMovie();
  238.         }
  239.  
  240.         g_State &= ~VCD_PAUSED;
  241.         g_State |= VCD_PLAYING;
  242.     }
  243.  
  244.     return TRUE;
  245. }
  246.  
  247.  
  248. /******************************Public*Routine******************************\
  249. * VcdPlayerRewindCmd
  250. *
  251. \**************************************************************************/
  252. BOOL
  253. VcdPlayerRewindCmd(
  254.     void
  255.     )
  256. {
  257.     if(pMpegMovie)
  258.     {
  259.         pMpegMovie->SeekToPosition((REFTIME)0,FALSE);
  260.     }
  261.  
  262.     return TRUE;
  263. }
  264.  
  265.